<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>权益维护</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link href="/node_modules/LobsterUIFrame/layuiadmin/layui/css/layui.css" rel="stylesheet" />
    <link href="/node_modules/LobsterUIFrame/layuiadmin/style/admin.css" rel="stylesheet" />
    <link href="/node_modules/LobsterUIFrame/layuiadmin/layui/css/modules/layui-icon-extend/iconfont.css"
        rel="stylesheet" />
    <script src="/node_modules/LobsterUIFrame/layuiadmin/layui/layui.js"></script>
</head>
<style>
.item_img{
    height: 100px;
}
</style>

<body>
    <div class="layui-fluid box">
        <form class="layui-form" lay-filter="formdata" id="formdata">
            <div class="layui-card">
                <div class="layui-card-body box">
                    <input type="hidden" name="RightId" value="0" />
                    <input type="hidden" name="DelFlag" value="0" />
                    <div class="layui-form-item active">
                        <label class="layui-form-label"><i style="color:red;">*&ensp; </i>权益标题</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" name="RightName" />
                        </div>

                    </div>
                    <div class="layui-form-item active">
                        <label class="layui-form-label">副标题</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" name="RightViceName" />
                        </div>
                    </div> 
                    <div class="layui-form-item active">
                        <label class="layui-form-label">介绍</label>
                        <div class="layui-input-block">
                            <textarea type="text" class="layui-input" name="Introduce"
                                style="width: 100%;height: 100px;"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item active">
                        <label class="layui-form-label">权益图片：</label>
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <div class="layui-inline">
                                    <button type="button" class="layui-btn" id="btnUpIcon">选择图片</button>
                                </div>
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img item_img" src="../resource/bgImg.jpg" id="ImgUrl">
                                </div>
                                <input type="hidden" name="ImgUrl"/> 
                            </div>
                        </div>
                    </div>
                </div>
            </div>
    </div>
    </form>
    </div>
</body>

</html>
<script>
    layui.config({
        base: '/node_modules/LobsterUIFrame/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    });

    layui.define(['index', 'layer', 'form', 'element', 'table', 'laydate','upload'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var $ = layui.$;
        var form = layui.form;
        var laytpl = layui.laytpl;
        var upload=layui.upload;
        var controller = {
            data: {
                model: {
                },
            },
            init: function () {
                var self = this;
                if (parent.selectdata) {
                    self.data.model = parent.selectdata;
                    form.val("formdata", JSON.parse(JSON.stringify(self.data.model)));
                    $("#ImgUrl").attr("src",self.data.model.ImgUrl);
                }
                self.getUploadUrl(function () {
                    self.uploadData();
                });
                self.initEvent();
            },
            getbaseurl: function (fun) {
                var url = "/lowcode/APP20210728143245471/member/?view=layui&fun=" + fun;
                return url;
            },
            //页面加载
            initEvent: function () {
                var self = this; 
                parent.getResult = function () {
                    self.data.model = form.val("formdata");
                    if (!self.data.model.RightName) {
                        layer.msg("权益标题不能为空");
                        return;
                    } 
                    return self.data.model;
                }
            },
            getUploadUrl: function (func) {
                var self = this;
                var url = this.getbaseurl("getUploadUrl");
                admin.req({
                    url: url,  //控制器名称，方法名称
                    data: {},
                    done: function (res) {
                        console.log(res);
                        self.data.uploadUrl = res.data.url + "&fileType=1";
                        if (func) {
                            func();
                        }
                    }
                });
            },
            uploadData: function () {
                var self = this;
                upload.render({
                    type: 'post',
                    elem: "#btnUpIcon",
                    url: self.data.uploadUrl,
                    data: {
                    },
                    done: function (res) {
                        console.log(res);
                        if (res.code == 0) {
                            self.data.model.Logo = res.data.url;
                            $('#ImgUrl').attr("src", res.data.url); //图片链接（base64）
                            $("[name='ImgUrl']").val(res.data.url); //图片链接（base64）
                        }
                    }
                });
            },
        }
        controller.init();
    });
</script>